package com.luyuan.crm.question.web;

import javax.annotation.Resource;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.luyuan.crm.question.model.Question;
import com.luyuan.crm.question.model.QuestionExtend;
import com.luyuan.crm.question.model.QuestionField;
import com.luyuan.crm.question.service.QuestionExtendService;
import com.luyuan.crm.question.service.QuestionService;
import com.ruijie.web.jsf.action.BaseAction;

@Component("addQuestionExtendAction")
@Scope("view")
public class AddQuestionExtendAction extends BaseAction implements InitializingBean {

    private Question question;

    private QuestionExtend questionExtend = new QuestionExtend();

    @Resource(name = "questionService")
    private QuestionService questionService;

    private QuestionField questionFieldType;

    @Resource(name = "questionExtendService")
    private QuestionExtendService questionExtendService;

    public void addQuestionExtend() {
        questionExtend.setQuestion(question);
        questionExtend.setItemType(questionFieldType);
        questionExtendService.saveQuestionExtend(questionExtend);

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        String id = getRequestParameter("uuid");
        if (id != null) {
            question = questionService.safeGet(Long.parseLong(id));
        }
    }

    public QuestionField getQuestionFieldType() {
        return questionFieldType;
    }

    public void setQuestionFieldType(QuestionField questionFieldType) {
        this.questionFieldType = questionFieldType;
    }

    public Question getQuestion() {
        return question;
    }

    public void setQuestion(Question question) {
        this.question = question;
    }

    public QuestionExtend getQuestionExtend() {
        return questionExtend;
    }

    public void setQuestionExtend(QuestionExtend questionExtend) {
        this.questionExtend = questionExtend;
    }

}
